package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.MultiAddrMapper;
import com.gxa.p2p.mapper.UserInfoMapper;
import com.gxa.p2p.pojo.UserInfo;
import com.gxa.p2p.service.UserInfoService;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class UserInfoServiceImpl implements UserInfoService {
    @Resource
    UserInfoMapper userInfoMapper;
    // 图片地址查询
    @Resource
    MultiAddrMapper multiAddrMapper;
    /**
     * 查询用户个人信息
     * @param id
     * @return
     */
    @Override
    public UserInfo findInfo(Integer id) {
        UserInfo userInfo = userInfoMapper.selectByUserId(id);
        System.out.println(userInfo);
        if(userInfo != null && !"".equals(userInfo.getAvatar())){
        // 如果对象不为空且头像不为空,对图片地址进行拼接
            userInfo.setAvatar(multiAddrMapper.selectImgAddr().getAddress()+userInfo.getAvatar());
        }
        // 返回对象
        return userInfo;
    }

    /**
     * 添加个人信息
     * @param userInfo
     * @return
     */
    @Override
    public Boolean saveUserInfo(UserInfo userInfo) {
        return userInfoMapper.insertSelective(userInfo) > 0;
    }

    /**
     * 更新用户个人信息
     * @param userInfo
     * @return
     */
    @Override
    public Boolean updateInfo(UserInfo userInfo) {
        return userInfoMapper.updateByPrimaryKeySelective(userInfo)>0;
    }



    /**
     * 通过userid来更新邮箱信息
     * @param
     * @return
     */
    @Override
    public Boolean updateById(Integer user_id , String email) {
        return userInfoMapper.updateById(user_id,email)>0;

    }
}
